Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
What is the dart equivalent to Swift “extensions”?

Keyword/reserved word extension allow code to be much cleaner by using an existing class in the standard frameworks without subclassing them. Is there a keyword in Dart that allows the same behavior?

extension Double {
    var mm: Double { return self / 1_000.0 }
}

let oneInch = 25.4.mm
print("One inch is \(oneInch) meters")
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

They are finally here 🥳

Since dart version 2.6 (not 100% sure).

 class Foo { printFoo() { print("Foo"); } } extension Bar on Foo { printBar() { print("Bar"); } } void main() { final foo = Foo(); foo.printFoo(); foo.printBar(); }

fingerprints:

foo

Pub

You can try it on dart pad.

over 4 years ago · Santiago Trujillo Relatório

0

Extension methods are currently being implemented into the language.

https://github.com/dart-lang/language/projects/1#card-18758939

Specifications document

https://github.com/dart-lang/language/blob/master/accepted/future-releases/static-extension-methods/feature-specification.md

over 4 years ago · Santiago Trujillo Relatório

0

TL;DR: Sadly, Dart doesn't support extension methods.

In the Dart repository, there's an issue about how to add new functionality to existing types for that. More specifically, there are issues for extension methods and extension types.

Of course, you can always use new classes that extend existing classes introduce new functionality on top of them. However, that only works for non-primitive classes, so let's hope for the best. Your best shot probably is to upvote the issues linked above.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda